import React from 'react'; 
import { BrowserRouter as Router, Route, Switch, Redirect } from 'react-router-dom';
import  './style.css';
import Login from './Login';
import Display from './Display';

const PrivateRoute = ({component:Com,...rest}) => {
  return <Route {...rest} render={({location})=>{
      const userinfo = localStorage.getItem('isLogin')
      if(userinfo) {
          return <Com />
      } else {
          return <Redirect to={{
              pathname: '/login',
              state: location.pathname
          }} />
      }
  }}/>
}

const App = () => {
  return(
    <Router>
      <Switch>
        <Route path='/login' component={Login} />
        <PrivateRoute path='/' component={Display} />
      </Switch>
    </Router>
  )
}

export default App;
